home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Plug-Ins / SubroutineUses.pl < prev   
Encoding:
Text File  |  2003-04-15  |  1.9 KB  |  70 lines

  1. #Name: Subroutine Uses
  2. #Description: Shows where each subroutine is used within the same script under "sub" node of code explorer (\optiperl\plug-ins\SubroutineUses.pl)
  3. #Icon: %opti%Tools.icl,148
  4. #Button: Explorer / Main menu
  5.  
  6. use Win32::OLE;
  7.  
  8. sub Initialization {
  9.  
  10.  $PlugID = $_[0];
  11.  #Get plug id. Will be used later
  12.  $optiperl =  Win32::OLE->new('OptiPerl.Application');
  13.  #get reference to application
  14.  $treeview = $optiperl->CodeExplorer;
  15.  #get reference to code explorer treeview
  16.  $subroutinenode = $treeview->MainNode(4);
  17.  #get the 4th (0-index) main node (subroutines)
  18.  
  19.  #Now iterate all subnodes of subroutine nodes
  20.  #to get all subroutines used. We will create a
  21.  #hash with them.
  22.  my $node = $treeview->GetFirstChild($subroutinenode);
  23.  #get first child of subroutine node
  24.  while (defined $node) {
  25.  #While the node is defined,
  26.   $hash{$node->Caption} = $node;
  27.   #add the subroutine name as key with the node as value
  28.   $node = $treeview->GetNext($node,1);
  29.   #get the next node
  30.  }
  31.  
  32.  $optiperl->QuickSave;
  33.  #Quick save active file. See help file for more information
  34.  $filename = $optiperl->ActiveDocument->Filename;
  35.  #Get the filename
  36.  $line = 0;
  37.  open(FILE, $filename);
  38.  while (<FILE>)
  39.  {
  40.     while ((my $key,my $node) = each %hash)
  41.     #for each item in the subroutine hash:
  42.     {
  43.         if ((index $_,$key) >= 0) {
  44.         #is the text in the line?
  45.          $newnode=$treeview->AddNode($node);
  46.          #add a child node under the node with the subroutine
  47.          $newnode->{Caption} = $_;
  48.          $newnode->{Path} = $filename;
  49.          $newnode->{Hint} = $_;
  50.          $newnode->{Line} = $line;
  51.         }
  52.     }
  53.     $line++;
  54.  }
  55.  close(FILE);
  56.  
  57.  $optiperl->EndPlugIn($PlugID);
  58.  #Finished. Note that this plug-in is not ment to
  59.  #run continually, so the above terminates it right after
  60.  #it runs.
  61. }
  62.  
  63.  
  64. sub Finalization {
  65. }
  66.  
  67. if (! defined $valid_plugin) {
  68.  #enter here the subroutines you want to test.
  69.  Initialization;
  70. }